<route>
    {
        meta: {
            layout: 'index',
            title:'工程事故复杂快报'
        }
    }  
</route>
<template>
  <div>
    <a-card>
      <div>
        <a-row v-if="selectedReport">
          <a-button type="primary" style="margin-left: auto; margin-bottom: 10px; margin-right: 10px; width: 100px"
            @click="doReturn">返回</a-button>
        </a-row>
      </div>
      <div v-if="!selectedReport">
        <a-tabs v-model:activeKey="activeKey">
          <a-tab-pane key="1" tab="信息录入">
            <div style="margin-right: 30px">
              <a-form :model="params" name="basic" :label-col="{ span: 8 }">
                <a-card>
                  <template #title>
                    <span>基础信息<span style="color: green">（提示：<span style="color: red">*</span> 代表必传内容）</span></span>
                  </template>
                  <template #extra>
                    <a-button type="link" size="large" style="width: 150px" @click="openUploader">导入数据</a-button>
                  </template>
                  <a-row>
                    <a-col :span="8">
                      <a-form-item label="井名" name="wellId" :rules="[{ required: true, message: '请输入井名' }]">
                        <a-input v-model:value="params.wellId" style="width: 170px" placeholder="请输入井名" />
                      </a-form-item>
                    </a-col>
                    <a-col :span="8">
                      <a-form-item label="油气田" name="gasName">
                        <a-input v-model:value="params.gasName" style="width: 170px" placeholder="请输入油气田" />
                      </a-form-item>
                    </a-col>
                    <a-col :span="8">
                      <a-form-item label="区域" name="region">
                        <a-input v-model:value="params.region" style="width: 170px" placeholder="请输入区域"></a-input>
                      </a-form-item>
                    </a-col>
                    <a-col :span="8">
                      <a-form-item label="井型" name="wellType">
                        <a-select v-model:value="params.wellType" style="width: 170px" placeholder="请选择井型">
                          <a-select-option v-for="item of wellType" :value="item.value" :key="item.value"
                            :label="item.label"></a-select-option>
                        </a-select>
                      </a-form-item>
                    </a-col>
                    <a-col :span="8">
                      <a-form-item label="井别" name="wellCategory">
                        <a-select v-model:value="params.wellCategory" style="width: 170px">
                          <a-select-option v-for="item of wellCategory" :value="item" :key="item">
                            {{ item }}</a-select-option>
                        </a-select>
                      </a-form-item>
                    </a-col>
                    <a-col :span="8">
                      <a-form-item label="钻井队号" name="teamNumber">
                        <a-input v-model:value="params.teamNumber" style="width: 170px" placeholder="请输入钻井队号"></a-input>
                      </a-form-item>
                    </a-col>
                    <a-col :span="8">
                      <a-form-item label="钻头尺寸" name="bitSize" :rules="[{ required: true, message: '请输入钻头尺寸' }]">
                        <a-input-group compact style="width: 270px">
                          <a-select v-model:value="params.bitSize" style="width: 129px">
                            <a-select-option v-for="item of bitSize" :value="item" :key="item">
                              {{ item }}</a-select-option>
                          </a-select>
                          <a-input value="mm" disabled style="width: 50px; height: 32px" />
                        </a-input-group>
                      </a-form-item>
                    </a-col>
                    <a-col :span="8">
                      <a-form-item label="作业井深" name="operatingWellDepth">
                        <a-input-number placeholder="请输入作业井深" v-model:value="params.operatingWellDepth"
                          style="width: 170px" :min="0" addon-after="m" />
                      </a-form-item>
                    </a-col>
                    <a-col :span="8">
                      <a-form-item label="钻井液密度" name="fluidDensity">
                        <a-input placeholder="钻井液密度" v-model:value="params.fluidDensity" style="width: 170px"
                          addon-after="g/cm^3"></a-input>
                      </a-form-item>
                    </a-col>
                    <a-col :span="8">
                      <a-form-item label="钻井液类型" name="fluidType">
                        <!-- <a-select v-model:value="params.fluidType" style="width: 170px">
                          <a-select-option v-for="item of fluidType" :value="item" :key="item">
                            {{ item }}</a-select-option></a-select> -->
                        <a-input v-model:value="params.fluidType" style="width: 170px" placeholder="请输入钻井液类型"></a-input>
                      </a-form-item>
                    </a-col>
                    <a-col :span="8">
                      <a-form-item label="最大井斜" name="maxDeviation">
                        <a-input v-model:value="params.maxDeviation" style="width: 170px" addon-after="°"
                          placeholder="请输入最大井斜" />
                      </a-form-item>
                    </a-col>
                    <a-col :span="8">
                      <a-form-item label="钻井液粘度" name="viscosity">
                        <a-input v-model:value="params.viscosity" style="width: 170px" addon-after="s"
                          placeholder="请输入钻井液粘度"></a-input>
                      </a-form-item>
                    </a-col>
                    <a-col :span="8">
                      <a-form-item label="项目部" name="projectDepartment">
                        <dept-select-tree :deptId="params.projectDepartment" @confirm="getProjDept"
                          style="width: 170px"></dept-select-tree>
                      </a-form-item>
                    </a-col>
                    <a-col :span="8">
                      <a-form-item label="施工队伍" name="constructionTeam">
                        <!-- <team-select-tree></team-select-tree> -->
                        <a-input v-model:value="params.constructionTeam" style="width: 170px"
                          placeholder="请输入施工队伍"></a-input>
                      </a-form-item>
                    </a-col>
                    <a-col :span="8">
                      <a-form-item label="作业类别" name="jobClass">
                        <a-select v-model:value="params.jobClass" style="width: 170px">
                          <a-select-option v-for="item of jobClass" :value="item" :key="item">
                            {{ item }}</a-select-option>
                        </a-select>
                      </a-form-item>
                    </a-col>
                    <a-col :span="8">
                      <a-form-item label="施工工艺" name="craft">
                        <a-select v-model:value="params.craft" style="width: 170px">
                          <a-select-option v-for="item of craft" :value="item" :key="item">{{ item }}</a-select-option>
                        </a-select>
                      </a-form-item>
                    </a-col>
                    <a-col :span="8">
                      <a-form-item label="电缆信息" name="cable">
                        <a-button v-model:value="params.cable" style="width: 170px" @click="openToolModal('cable')">
                          {{ buttonCable }}</a-button>
                      </a-form-item>
                    </a-col>
                    <a-col :span="8">
                      <a-form-item label="弱点设置(lbs)" name="weaknessSettings">
                        <a-select v-model:value="params.weaknessSettings" style="width: 170px" allowClear>
                          <a-select-option v-for="item of weakRatio" :value="`${item} +/- 3%`" :key="item">
                            {{ `${item} +/- 3% 磅` }}</a-select-option>
                        </a-select>
                      </a-form-item>
                    </a-col>
                    <a-col :span="8">
                      <a-form-item label="复杂类型" name="complexType">
                        <a-select v-model:value="params.complexType" style="width: 170px">
                          <a-select-option v-for="item of complexType" :value="item" :key="item">
                            {{ item }}</a-select-option>
                        </a-select>
                      </a-form-item>
                    </a-col>
                    <a-col :span="8">
                      <a-form-item label="仪器串信息" name="combination" :rules="[{ required: true, message: '请选择仪器串信息' }]">
                        <a-button style="width: 170px" @click="openToolModal('combination')">
                          {{ buttonCombination }}</a-button>
                      </a-form-item>
                    </a-col>
                    <a-col :span="8">
                      <a-form-item label="仪器原值" name="instrumentOriginalValue">
                        <a-select style="width: 170px" v-model:value="params.instrumentOriginalValue">
                          <a-select-option v-for="item of instrumentOriginalValue" :value="item" :key="item">
                            {{ item }}</a-select-option>
                        </a-select>
                      </a-form-item>
                    </a-col>
                    <a-col :span="8">
                      <a-form-item label="鱼头位置" name="headPosition">
                        <a-input-number placeholder="请输入鱼头位置" style="width: 170px" v-model:value="params.headPosition"
                          :min="0" addon-after="m" />
                      </a-form-item>
                    </a-col>
                    <a-col :span="8">
                      <a-form-item label="落鱼信息" name="fishInformation">
                        <a-input v-model:value="params.fishInformation" style="width: 170px" placeholder="请输入落鱼信息" />
                      </a-form-item>
                    </a-col>
                    <a-col :span="8">
                      <a-form-item label="放射源信息" name="radioactiveSourceInformation">
                        <a-select placeholder="请输入放射源信息" style="width: 170px"
                          v-model:value="params.radioactiveSourceInformation" mode="multiple">
                          <a-select-option v-for="item of radioactiveSource" :value="item.value" :key="item.value"
                            :label="item.label"></a-select-option>
                        </a-select>
                      </a-form-item>
                    </a-col>
                    <a-col :span="8">
                      <a-form-item label="作业空间" name="workSpace">
                        <a-select v-model:value="params.workSpace" style="width: 170px">
                          <a-select-option v-for="item of workSpace" :value="item" :key="item">
                            {{ item }}</a-select-option>
                        </a-select>
                      </a-form-item>
                    </a-col>
                    <a-col :span="8">
                      <a-form-item label="遇卡仪器" name="stuckInstruments">
                        <a-select v-model:value="params.stuckInstruments" style="width: 170px" mode="multiple">
                          <a-select-option v-for="item of stuckInstruments" :value="item" :key="item">
                            {{ item }}</a-select-option>
                        </a-select>
                      </a-form-item>
                    </a-col>
                    <a-col :span="8">
                      <a-form-item label="遇卡描述" name="description">
                        <a-select v-model:value="params.description" style="width: 170px">
                          <a-select-option v-for="item of description" :value="item" :key="item">
                            {{ item }}</a-select-option>
                        </a-select>
                      </a-form-item>
                    </a-col>
                    <a-col :span="8">
                      <a-form-item label="电缆张力" name="tension">
                        <a-select v-model:value="params.tension" style="width: 170px">
                          <a-select-option v-for="item of tension" :value="item" :key="item">
                            {{ item }}</a-select-option>
                        </a-select>
                      </a-form-item>
                    </a-col>
                    <a-col :span="8">
                      <a-form-item label="卡点" name="points">
                        <a-select v-model:value="params.points" style="width: 170px">
                          <a-select-option v-for="item of points" :value="item" :key="item">
                            {{ item }}</a-select-option>
                        </a-select>
                      </a-form-item>
                    </a-col>
                    <a-col :span="8">
                      <a-form-item label="遇卡原因" name="cause">
                        <a-select v-model:value="params.cause" style="width: 170px" mode="multiple">
                          <a-select-option v-for="item of cause" :value="item" :key="item">
                            {{ item }}</a-select-option>
                        </a-select>
                      </a-form-item>
                    </a-col>
                    <a-col :push="2" :span="14">
                      <a-space v-for="(casing, index) in dynamicValidateForm.casings" :key="casing.id"
                        style="display: flex; margin-left: -180px" align="baseline">
                        <a-form-item label="套管程序" :name="['casings', index, 'depth']">
                          <a-input-group style="width: 600px" compact>
                            <a-input-number v-model:value="casing.outerDiameter" class="site-input-right"
                              style="width: 220px; text-align: center" placeholder="请输入套管外径" :min="0" addon-after="mm" />
                            <a-input v-model:value="value13" class="site-input-split"
                              style="width: 35px; pointer-events: none" placeholder="~" disabled />
                            <a-input-number style="width: 210px" v-model:value="casing.deep" placeholder="请输入套管深度"
                              :min="0" addon-after="m"></a-input-number>
                          </a-input-group>
                        </a-form-item>
                        <a-form-item>
                          <a-button style="margin-left: 80px; width: 130px" v-if="dynamicValidateForm.casings.length > 1"
                            class="dynamic-delete-button" :disabled="dynamicValidateForm.casings.length === 1"
                            type="dashed" block @click="removeCasings(casing)">
                            <MinusCircleOutlined />删除行
                          </a-button>
                        </a-form-item>
                      </a-space>
                    </a-col>
                    <a-button type="dashed" style="width: 100%" block @click="addDomain()">
                      <PlusOutlined />添加套管程序
                    </a-button>
                  </a-row>
                </a-card><br />
                <a-card>
                  <template #title>
                    <span>其他信息</span>
                  </template>
                  <a-row>
                    <a-col :pull="4" :span="24">
                      <a-form-item label="工程复杂经过" name="complexPassage">
                        <a-textarea v-model:value="params.complexPassage" style="width: 100%" :rows="3" />
                      </a-form-item>
                    </a-col>
                    <a-col :pull="4" :span="24">
                      <a-form-item label="初步原因分析" name="causeAnalysis">
                        <a-textarea v-model:value="params.causeAnalysis" style="width: 100%" :rows="3" />
                      </a-form-item>
                    </a-col>
                    <a-col :pull="4" :span="24">
                      <a-form-item label="井筒状况" name="wellboreCondition">
                        <a-textarea v-model:value="params.wellboreCondition" style="width: 100%" :rows="3" />
                      </a-form-item>
                    </a-col>
                    <a-col :pull="4" :span="24">
                      <a-form-item label="下步处置方案" name="nextSteps">
                        <a-textarea v-model:value="params.nextSteps" style="width: 100%" :rows="3" />
                      </a-form-item>
                    </a-col>
                  </a-row>
                  <a-row>
                    <a-col :span="12">
                      <a-form-item label="联系方式" name="phoneNumber">
                        <a-input style="width: 170px" v-model:value="params.phoneNumber" placeholder="138xxxxxxxx" />
                      </a-form-item>
                    </a-col>
                    <a-col :span="8">
                      <a-form-item label="填报单位" name="unit">
                        <a-input style="width: 170px" v-model:value="params.unit" placeholder="中国石油测井公司" />
                      </a-form-item>
                    </a-col>
                  </a-row>
                </a-card>
              </a-form>
              <a-button type="primary" style="margin-top: 10px; width: 100%" @click="subConfirm">确认提交</a-button>
            </div>
          </a-tab-pane>
          <a-tab-pane key="2" tab="上传记录">
            <HistoryInfo :result="result" @editInfo="editInfo"></HistoryInfo>
          </a-tab-pane>
        </a-tabs>
        <!-- 文件导入 -->
        <AntdConfirmModal title="导入文件" ref="modalRef" width="600px" @confirm="submitSelect">
          <a-form :model="form" :label-col="{ span: 8 }">
            <a-row>
              <a-col :pull="1" :span="21">
                <a-form-item label="Word文件上传">
                  <a-upload-dragger withCredentials v-model:fileList="wordList" style="width: 320px" name="file"
                    :before-upload="wordUpload" @remove="handleRemove('word')" :maxCount="1">
                    <p class="ant-upload-drag-icon">
                      <inbox-outlined></inbox-outlined>
                    </p>
                    <p class="ant-upload-text">点击或者拖拽Word文件到此处上传</p>
                  </a-upload-dragger>
                </a-form-item>
              </a-col>
            </a-row>
            <a-row>
              <a-col :pull="1" :span="21">
                <a-form-item label="PDF文件上传">
                  <a-upload-dragger withCredentials v-model:fileList="pdfList" style="width: 320px" name="file"
                    :before-upload="pdfUpload" @remove="handleRemove('pdf')" :maxCount="1">
                    <p class="ant-upload-drag-icon">
                      <inbox-outlined></inbox-outlined>
                    </p>
                    <p class="ant-upload-text">点击或者拖拽PDF文件到此处上传</p>
                  </a-upload-dragger>
                </a-form-item>
              </a-col>
            </a-row>
          </a-form>
        </AntdConfirmModal>

        <!-- 套管选择弹窗 -->
        <!-- <AntdConfirmModal title="套管选择" ref="casingModalRef" width="700px" :keepSlot="false" @confirm="addCasing()">
        <casing-popup-page></casing-popup-page>
      </AntdConfirmModal> -->
        <!-- 电缆选择弹窗 -->
        <AntdConfirmModal title="电缆选择" ref="cableModalRef" width="1000px" :keepSlot="false" @confirm="addCable">
          <cable-popup-page></cable-popup-page>
        </AntdConfirmModal>
        <!-- 选择仪器串推荐组合弹窗 -->
        <AntdConfirmModal :showConfirm="false" title="仪器串选择" ref="combinationModalRef" width="1200px">
          <InstrumentInfo :combinationId="params.combinationId" :sOpen="sOpen" @getCombId="getCombId"> </InstrumentInfo>
        </AntdConfirmModal>
      </div>
      <!-- 工程报告详细信息 -->
      <view v-if="selectedReport">
        <AccidentDetail :reportId="selectedReport"></AccidentDetail>
      </view>
    </a-card>
  </div>
</template>
<script setup>
import { PlusOutlined, InboxOutlined } from "@ant-design/icons-vue";
import DeptSelectTree from "@/custom/salvage/components/DeptSelectTree.vue";
import HistoryInfo from "../accidentReport/drawer/historyInfo.vue";
import CablePopupPage from "@/custom/well/components/CablePopupPage";
import InstrumentInfo from "./drawer/InstrumentInfo.vue";
import AccidentDetail from "./detail";
import { WellDatas } from "@/custom/salvage/constant/address.js"; //新建井判断
import WellCable from "@/api/tool/cable.js";
import AccidentApi from "@/api/salvage/accidentAlert";
import WellCombination from "@/api/tool/combination.js";
import { wellType, wellCategory, craft, complexType, bitSize, radioactiveSource, jobClass, instrumentOriginalValue, fluidType, weakRatio, projectDepartment, } from "@/custom/salvage/constant/report.js";
import { workSpace, stuckInstruments, description, tension, points, cause } from '../../../constant/select.js'
import request from "@/utils/request";
import moment from "moment";
import "moment/locale/zh-cn";
import dayjs from "dayjs";
import "dayjs/locale/zh-cn";
import useApp from "@/hooks";
import useUserStore from "@/store/modules/user";
const userStore = useUserStore();
const { $, proxy } = useApp();
const buttonCombination = ref("选择仪器串");
const buttonCable = ref("选择电缆");
const params = ref({
  wellId: "",
  gasName: "",
  region: "",
  wellCategory: "生产井",
  wellType: "定向井",
  teamNumber: "",
  complexType: "穿心解卡",
  operatingWellDepth: "",
  maxDeviation: "",
  bitSize: "215.9",
  cableId: "",
  combinationId: "",
  jobClass: "放射性",
  headPosition: "",
  fishInformation: "",
  casingList: [],
  fluidDensity: "",
  viscosity: "",
  fluidType: "聚合物",
  projectDepartment: "",
  constructionTeam: "",
  craft: "电缆测井",
  // instrumentStringFileId: '',
  instrumentOriginalValue: "仪器原值<500万元",
  radioactiveSourceInformation: [],
  weaknessSettings: "",
  complexPassage:
    "该井x月x日晚x点,测完声感和阵列侧向后通井。x月x日凌晨x通井结束后开始进行放射性施工，x月x日9:10仪器下至X米遇阻，正常上提X米后再次尝试下放，上提过程中无挂卡显示。下放至X米后再次遇阻。再次上提活动仪器，到X处遇卡，拉至总张力X磅，未能解卡。反复试拉X次，总张力由X磅涨到X磅，仪器未活动，最终拉至X磅等待穿心解卡。",
  wellboreCondition: "x月x日进行声感阵列侧向施工时，通井时钻具无挂卡显示。",
  causeAnalysis: "该处为泥岩，地层比较致密，容易垮塌，井径数值变化不大，井斜X度，怀疑掉块导致遇卡。",
  nextSteps: "穿心解卡",
  fillPeople: "",
  phoneNumber: "",
  unit: "",
  fillDate: "",
  workSpace: '',
  stuckInstruments: [],
  description: '',
  tension: '',
  points: '',
  cause: [],

});
const activeKey = ref("1");
const sOpen = ref(false);
const defaultParams = ref($.freeStore(params.value));
const modalRef = ref(null);
const state = ref("新建");
const casingModalRef = ref(null);
const cableModalRef = ref(null);
const result = ref(null);
const combinationModalRef = ref(null);
const wordList = ref([]);
const pdfList = ref([]);
const selectedReport = ref(false);
const dynamicValidateForm = ref({
  casings: [],
});
const fileForm = ref({
  wordFile: null,
  pdfFile: null,
  bucketName: "importPre",
});
watch(() => activeKey.value, () => {
  //历史信息
  let uid = localStorage.getItem('userId')
  if (activeKey.value == "2") {
    const query = { order: "DESC", pageNum: "1", pageSize: "99999", searchKey: "", sortBy: "id", };
    if (userStore.isAdmin !== true) {
      // 不是超级管理员时
      query.createUserId = uid
    }
    AccidentApi.queryLastList(query).then((res) => {
      console.log('watch-历史记录', res);
      result.value = res.content;
    });
  }
});
// 打开导入文件窗口
function openUploader() {
  modalRef.value.openModal();
}
// word文件导入
const wordUpload = (file) => {
  if (
    file.type !== "application/vnd.openxmlformats-officedocument.wordprocessingml.document" &&
    file.type !== "application/msword"
  ) {
    $.showToast({
      title: "请上传word类型的文件",
      icon: "error",
    });
    return false;
  } else {
    fileForm.value.wordFile = file;
  }
};
// pdf文件导入
const pdfUpload = (file) => {
  if (file.type !== "application/pdf") {
    $.showToast({
      title: "请上传pdf类型的文件",
      icon: "error",
    });
    return false;
  } else {
    fileForm.value.pdfFile = file;
  }
};
// 移除文件
const handleRemove = (e) => {
  if (e == "word") {
    fileForm.value.wordFile = null;
  } else if (e == "pdf") {
    fileForm.value.pdfFile = null;
  }
};
// 添加一个套管
const addDomain = () => {
  dynamicValidateForm.value.casings.push({
    outerDiameter: null,
    deep: null,
    name: `套管${dynamicValidateForm.value.casings.length + 1}`,
    id: Date.now(),
  });
};
// 移出一个套管
const removeCasings = (item) => {
  let index = dynamicValidateForm.value.casings.indexOf(item);
  if (index !== -1) {
    dynamicValidateForm.value.casings.splice(index, 1);
  }
};
// 打开工具弹窗
function openToolModal(e) {
  console.log("openToolModal", e);
  if (e == "casing") {
    casingModalRef.value.openModal();
  } else if (e == "cable") {
    cableModalRef.value.openModal();
  } else if (e == "combination") {
    combinationModalRef.value.openModal();
    if (params.value.combinationId) {
      sOpen.value = true;
    } else {
      sOpen.value = false;
    }
  }
}
// 仪器串信息展示
function showCombination(id) {
  if (id) {
    WellCombination.queryOne(id).then((res) => {
      console.log("仪器串信息", res);
      buttonCombination.value = `已选择${res.combinationName}`;
    });
  } else {
    buttonCombination.value = "选择仪器串";
  }
}
// 部门信息
function getProjDept(e) {
  console.log("项目部", e);
  params.value.projectDepartment = e;
}
// 获取仪器串id
function getCombId(e) {
  params.value.combinationId = e;
  combinationModalRef.value.closeModal();
  showCombination(e);
}
// 添加电缆信息
function addCable() {
  let cableData = JSON.parse(localStorage.getItem("selectCables"));
  console.log("cableData", cableData);
  params.value.cableId = cableData[0].id;
  showCable(cableData[0].id);
  cableModalRef.value.closeModal();
}
// 电缆信息展示
function showCable(id) {
  if (id) {
    WellCable.queryOne(id).then((res) => {
      console.log(res);
      buttonCable.value = `已选择${res.diameter}mm的电缆`;
    });
  } else {
    buttonCable.value = "选择电缆";
  }
}
// 上传文件提交
function submitSelect() {
  let formData = new FormData();
  if (fileForm.value.wordFile !== null && fileForm.value.pdfFile !== null) {
    formData.append("wordFile", fileForm.value.wordFile);
    formData.append("pdfFile", fileForm.value.pdfFile);
    request.post("/salvage/accidentAlert/template", formData, {
      headers: {
        "Content-Type": "multipart/form-data",
      },
    }).then((res) => {
      console.log("upload", res);
      if (!res.causeAnalysis) {
        res.causeAnalysis = "该处为泥岩，地层比较致密，容易垮塌，井径数值变化不大，井斜X度，怀疑掉块导致遇卡。";
      }
      if (!res.complexPassage) {
        res.complexPassage =
          "该井x月x日晚x点,测完声感和阵列侧向后通井。x月x日凌晨x通井结束后开始进行放射性施工，x月x日9:10仪器下至X米遇阻，正常上提X米后再次尝试下放，上提过程中无挂卡显示。下放至X米后再次遇阻。再次上提活动仪器，到X处遇卡，拉至总张力X磅，未能解卡。反复试拉X次，总张力由X磅涨到X磅，仪器未活动，最终拉至X磅等待穿心解卡。";
      }
      if (!res.wellboreCondition) {
        res.wellboreCondition = "x月x日进行声感阵列侧向施工时，通井时钻具无挂卡显示。";
      }
      if (!res.nextSteps) {
        res.nextSteps = "穿心解卡";
      }
      if (res.radioactiveSourceInformation == null) {
        res.radioactiveSourceInformation = [];
      }
      params.value = res;
      dynamicValidateForm.value.casings = params.value.casingList;
      console.log("params", params.value);
      $.showToast({
        title: "上传成功",
        icon: "success",
      });
      modalRef.value.closeModal();
    });
  } else {
    $.showToast({
      title: "文件不全，请导入word文件以及pdf文件，二者缺一不可",
      icon: "warn",
    });
  }
}
// 编辑
function editInfo(data) {
  state.value = "编辑";
  activeKey.value = "1";
  console.log("editInfo", data);
  params.value = data;
  // 套管
  dynamicValidateForm.value.casings = [];
  let casingStart = 0;
  data.casingList?.forEach((e) => {
    dynamicValidateForm.value.casings.push({
      outerDiameter: e.outerDiameter,
      start: casingStart,
      deep: e.deep,
      name: e.name,
      id: e.deep,
    });
    casingStart = e.deep;
  });
  showCable(data.cableId);
  showCombination(data.combinationId);
}
// 提交
function subConfirm() {
  params.value.casingList = dynamicValidateForm.value.casings;
  params.value.fillPerson = localStorage.getItem('userName')// 填报人
  let currentTime = new Date();
  params.value.fillDate = moment(currentTime).format("YYYY-MM-DD"); //填报时间
  // 判空
  if (params.value.wellId == "") { $.showToast({ title: "井名不允许为空", icon: "warn" }); }
  else if (!params.value.cableId) { $.showToast({ title: "请选择电缆", icon: "warn" }); }
  else if (!params.value.combinationId) { $.showToast({ title: "请选择仪器串", icon: "warn" }); }
  else if (params.value.bitSize == 0) { $.showToast({ title: "请输入钻头尺寸", icon: "warn" }); }
  else if (
    params.value.casingList.length == 0 ||
    params.value.casingList[params.value.casingList.length - 1].outerDiameter == null ||
    params.value.casingList[params.value.casingList.length - 1].deep == null
  ) {
    $.showToast({ title: "套管数据不允许为空", icon: "warn", });
  } else {
    if (state.value == "编辑") {
      AccidentApi.updateOne(params.value).then((res) => {
        $.showToast({
          title: "修改成功",
          icon: "success",
        });
        selectedReport.value = res.id;
      });
    } else {
      AccidentApi.createOne(params.value).then((res) => {
        console.log('createOne', res)
        params.value = $.freeStore(defaultParams.value);
        $.showToast({
          title: "新建成功",
          icon: "success",
        });
        WellDatas(res.id, res.wellId); // 新建井存在判断
        selectedReport.value = res.id;
      });
    }
    resetParams(params.value);
  }
}
// 重置params对象
function resetParams(obj) {
  for (let key in obj) {
    if (Array.isArray(obj[key])) {
      console.log("重置params数组", obj[key]);
      obj[key] = []; // 清空数组
    } else if (typeof obj[key] === "object" && obj[key] !== null) {
      resetParams(obj[key]); // 递归处理嵌套的对象
    } else {
      obj[key] = ""; // 重置属性
    }
  }
  state.value = "新建";
  dynamicValidateForm.value.casings = [];
  buttonCombination.value = "选择仪器串";
  buttonCable.value = "选择电缆";
}
// 返回
function doReturn() {
  selectedReport.value = false;
  resetParams(params.value);
}
</script>
